-
In Project Builder's browser, select Classes in the first column.
-
Choose File
New in Project.
-
Type Guest.java as the name of the file.
-
Click OK.
The newly created file contains a skeleton for a class called Guest.
-
Modify the code so it looks like this:
// Generated by the WebObjects Wizard ...
import com.apple.yellow.foundation.*;
import com.apple.yellow.eocontrol.*;
import com.apple.yellow.webobjects.*;
public class Guest extends EOCustomObject {
protected String guestName;
protected String email;
protected String comments;
Guest() {
guestName = "";
email = "";
comments = "";
}
}
A class stores information in its instance variables (also referred to as data members). Here you're declaring three instance variables for Guest: guestName, email, and comments. Note that these declarations are the same as those that appeared in the code for Main.java when you added the three variables using WebObjects Builder. In WebObjects, a component is also a class, specifically a subclass of the class WOComponent.
Java classes require a constructor to initialize an instance (or object) of a particular class whenever one is created. A constructor has the same name as the class and returns no value.
Whenever your application creates a new Guest class, its instance variables are initialized with empty strings, which is the default value if the user enters no data. (If you prefer, you can use different strings for these initial values.)
-
Save Guest.java by choosing Save from the File menu.
Saving the file lets WebObjects Builder know about your newly created Guest class.